<template>
  <div id="sign" v-if="show">
    <div class="bg"></div>
    <div class="modal interestModal selectTag" v-loading="loading">
      <div class="modalFavor">选择你喜欢的专题</div>
      <div
        class="modalTag "
        :class="item.selected ? 'InterSelected' : ''"
        v-for="(item, index) in modalList"
        :key="index"
        @click="selectInterest(item.tagId, index)"
      >
        {{ item.tagName }}-{{ item.tagContent }}
      </div>
      <div class="sign-btn interestBtn" @click="next">保存</div>
      <div class="clear-btn" @click="showModal">
        <img src="../assets/imgs/cha.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      modalType: 0,
      btnShow: true,
      show: false,
      list: [
        {
          content: "",
        },
      ],
      num: 0,
      question: [],
      grade: 0,
      time: 60,
      myTime: "",
      getIndex: -1,
      answerIndex: "",
      modalList: [],
      arr: [],
      isFather: false,
      loading: true,
      openid: "",
    };
  },
  created() {
    if (this.isToken()) {
      this.interestList();
    }
  },
  mounted() {
    this.getRem(1920, 100);
  },
  methods: {
    goFind() {
      this.$router.push({
        path: "/",
      });
    },
    //专题列表
    async interestList() {
      this.loading = true;
      const res = await this.$fetch(`/laiwen/interest/frontend/list`);
      this.loading = false;
      this.modalList = res.interestList;
      for (let i of this.modalList.keys()) {
        this.$set(this.modalList[i], "selected", false);
      }
      this.concernList();

      console.log(res);
    },
    //调用已关注的专题列表
    async concernList() {
      const res = await this.$fetch("/laiwen/interest/frontend/ilist", {});
      let indexArr = res.list.map((item) => item.tagId - 101);
      this.arr = res.list.map((item) => item.tagId);
      for (let i of indexArr.keys()) {
        this.modalList[indexArr[i]].selected = true;
      }
      console.log(res);
    },
    //选择专题
    selectInterest(id, index) {
      let res = [...this.modalList].find((item) => item.tagId == id);
      res.selected = !res.selected;
      if (res.selected) {
        this.arr.push(res.tagId);
      } else {
        for (let i in this.arr) {
          if (this.arr[i] == id) {
            this.arr.splice(i, 1);
          }
        }
      }
    },
    //保存专题
    async next() {
      if (this.arr.length == 0) {
        this.$message.error("亲亲请先选择专题哦");
        return false;
      }
      let obj = {};
      this.$set(obj, "ids", this.arr);
      const res = await this.$post(`/laiwen/interest/frontend/save`, obj);
      this.showModal();
      this.$parent.concernInterest();
    },
    showModal() {
      this.show = !this.show;
    },
  },
};
</script>

<style scoped>
#sign {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1;
}
img {
  width: 100%;
  height: 100%;
  flex-shrink: 0;
}
.modal .modalFavor {
  width: 1.6rem;
  height: 0.28rem;
  font-size: 0.2rem;
  font-family: PingFang SC;
  font-weight: bold;
  line-height: 0.28rem;
  color: rgba(9, 9, 9, 1);
  opacity: 1;
  margin-bottom: 0.24rem;
}
.modal .modalTag {
  width: 2.15rem;
  height: 0.46rem;
  background: rgba(255, 255, 255, 1);
  box-shadow: 0rem 0rem 0.05rem rgba(0, 0, 0, 0.16);
  border-radius: 0.44rem;
  margin-bottom: 0.16rem;
  font-size: 0.16rem;
  font-family: PingFang SC;
  font-weight: 400;
  color: rgba(152, 152, 152, 1);
  opacity: 1;
  align-self: flex-start;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.InterSelected {
  background: #fcec5b !important;
  color: #090909 !important;
}
.modal .modalTag:nth-of-type(even) {
  margin-left: 1.52rem;
}
.modal .modalTag:nth-of-type(odd) {
  margin-left: 0.69rem;
}
.modal .modalTag:nth-of-type(7) {
  margin-bottom: 0rem;
}
.selectTag {
  padding-left: 0rem !important;
  padding-right: 0rem !important;
}
.bg {
  width: 100%;
  height: 100%;
  opacity: 0.25;
  background: black;
  position: absolute;
  z-index: -1;
}
.selected {
  background: #ffd52f !important;
  color: #ffffff !important;
  border: 0.01rem solid transparent !important;
}

.modal {
  width: 4rem;
  min-height: 5rem;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  display: flex;
  align-items: center;
  position: relative;
  flex-direction: column;
  z-index: 9999;
  background: white;
  padding: 0.32rem;
  box-sizing: border-box;
  margin-top: 1.8rem;
  border-radius: 0.05rem;
}
.success {
  padding-top: 0rem;
}
.modal-btns {
  width: 4.36rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
.modalTitle {
  width: 100%;
  display: flex;
  font-size: 0.18rem;
  font-family: PingFang SC;
  font-weight: 400;
  color: rgba(9, 9, 9, 1);
  opacity: 1;
  position: relative;
  justify-content: space-between;
}
.interestBtn {
  margin-top: 0.32rem !important;
}
.quesIcon {
  width: 0.3rem;
  height: 0.3rem;
  opacity: 1;
  overflow: hidden;
  border-radius: 50%;
  position: absolute;
  right: 1.18rem;
}
.grade {
  width: 100%;
  height: 0.24rem;
  background: rgba(238, 238, 238, 1);
  opacity: 1;
  border-radius: 0.12rem;
  margin: 0.28rem 0rem;
}
.question {
  width: 100%;
  font-size: 0.2rem;
  font-family: PingFang SC;
  font-weight: bold;
  color: rgba(9, 9, 9, 1);
  opacity: 1;
  margin-bottom: 0.4rem;
}
.answer {
  display: flex;
  font-size: 0.19rem;
  font-family: PingFang SC;
  font-weight: 400;
  color: rgba(9, 9, 9, 1);
  opacity: 1;
  align-self: flex-start;
  max-width: 4.17rem;
  margin-bottom: 0.24rem;
}
.answer:nth-of-type(6) {
  margin-bottom: 0rem;
}
label {
  font-size: 0.19rem;
  font-family: PingFang SC;
  font-weight: 400;
  color: rgba(9, 9, 9, 1);
  opacity: 1;
  margin-left: 0.16rem;
}
.finish {
  background: #999999 !important;
  color: #ffffff !important;
}

image {
  width: 100%;
  display: block;
  height: 100%;
}
.modal-text {
  height: 0.2rem;
  font-size: 0.14rem;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 0.2rem;
  color: rgba(9, 9, 9, 1);
  opacity: 1;
}
.modal-btn {
  width: 0.88rem;
  height: 0.78rem;
  background: rgba(238, 238, 238, 1);
  opacity: 1;
  border-radius: 0.05rem;
  margin-top: 0.08rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: rgba(153, 153, 153, 1);
  cursor: pointer;
}
.modal-btn .gift-icon {
  width: 0.31rem;
  height: 0.31rem;
  margin-top: 0.13rem;
}
.gift-text {
  margin-top: 0.07rem;
  height: 0.2rem;
  font-size: 0.14rem;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 0.2rem;
  opacity: 1;
}
.sign-btn {
  background: #ffe300;
  opacity: 1;
  font-size: 0.16rem;
  font-family: PingFang SC;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 400;
  color: #303030;
  opacity: 1;
  cursor: pointer;
  margin-top: 0.39rem;
  width: 3.36rem;
  height: 0.42rem;
  opacity: 1;
  border-radius: 0.05rem;
}
.clear-btn {
  width: 0.24rem;
  height: 0.24rem;
  border-radius: 50%;
  opacity: 1;
  position: absolute;
  right: -0.28rem;
  top: -0.28rem;
  cursor: pointer;
}
/* 表示总长度背景色 */
progress::-webkit-progress-bar {
  background-color: #eeeeee;
  border-radius: 0.12rem;
}
progress::-webkit-progress-value {
  background: #ffd52f;
  border-radius: 0.2rem;
}

input[type="radio"] {
  width: 0.2rem;
  height: 0.2rem;
  position: relative;
  appearance: none;
  vertical-align: middle;
  outline: none !important;
}
input[type="radio"]::before {
  position: absolute;
  content: "";
  top: 50%;
  left: 0;
  margin-top: -0.1rem;
  width: 100%;
  height: 100%;
  width: 0.2rem;
  height: 0.2rem;
  background: rgba(255, 255, 255, 1);
  border: 0.01rem solid rgba(208, 208, 208, 1);
  opacity: 1;
  border-radius: 0.03rem;
}
input[type="radio"]:checked::before {
  position: absolute;
  content: "\2713";
  font-size: 0.2rem;
  font-weight: bold;
  text-align: center;
  color: white;
  background: #ffd52f;
  border: 0.01rem solid transparent;
  line-height: 0.2rem;
}
.modalIcon {
  width: 1.48rem;
  height: 1.48rem;
  opacity: 1;
  margin-top: 0.45rem;
  border-radius: 50%;
  overflow: hidden;
}
.modalPrompt {
  width: 2.34rem;
  height: 0.37rem;
  font-size: 0.26rem;
  font-family: PingFang SC;
  font-weight: bold;
  line-height: 0.37rem;
  color: rgba(9, 9, 9, 1);
  opacity: 1;
  margin: 0.48rem 0rem 0.24rem 0rem;
}
.modalText {
  width: 1.8rem;
  height: 0.28rem;
  font-size: 0.2rem;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 0.28rem;
  color: rgba(153, 153, 153, 1);
  opacity: 1;
}
.windowTop {
  width: 100%;
  height: 0.86rem;
  border-bottom: 0.01rem solid #eeeeee;
  position: relative;
}
.windowTitle {
  width: 0.64rem;
  height: 0.48rem;
  font-size: 0.16rem;
  font-family: PingFang SC;
  font-weight: bold;
  color: rgba(48, 48, 48, 1);
  position: absolute;
  bottom: 0;
  opacity: 1;
  border-bottom: 0.02rem solid #303030;
}
.Back {
  position: absolute;
  right: 0;
  bottom: 0;
  height: 0.48rem;
  font-family: PingFang SC;
  cursor: pointer;
  color: #6e6e6e;
  font-size: 0.16rem;
}
</style>
